<?php

namespace app\admin\controller;

use app\common\model\NewsTopic as NewsTopicModel;
use app\common\model\Member as MemberModel;
/**
 * 资讯评论控制器
 * Class NewsTopic
 * @package app\admin\controller
 */
class NewsTopic extends Base
{
    /**
     * [getIndex  获取评论]
     * @author [C。]
     * @return json
     */
    public function getIndex()
    {
        $param = input('param.');
        $model = new NewsTopicModel();
        $mmodel = new MemberModel();
        $this->getPageAndSize($param);
        $map = [];
        $user = $this->user;
        try{
            if (!empty($data['con'])) {
                $map['content'] = ['like', "%" . $data['con'] . "%"];
            }
            if(!empty($data['states'])){
                $map['states'] = $data['states'];
            }
            if(!empty($data['start']) || !empty($data['end'])){
                $map['create_time'] = ['between',[strtotime($data['start']),strtotime($data['end'])]];
            }
            $map['states'] = ['neq',-1];
            $map['newid'] = $param['newid'];
            $count = $model->getAllcount($map);//满足条件的总数
            $allpage = intval(ceil($count / $this->size));//总页数
            $lists = $model->getAll($map,$this->from, $this->size);
            foreach ($lists as $key => $v) {
                $lists[$key]['ctype'] = $v['parid'] > 0 ? '回复' : '原创';
                $lists[$key]['content'] = urldecode($v['content']);
                $res = $model->findOne($v['id'], 'parid');
                if (!empty($res)) {
                    $lists[$key]['reply'] = urldecode($res['content']);
                }
                if($v['parid'] == 0){
                    $user = $mmodel->findData($v['memid'],'id');
                }else{
                    $user = $mmodel->findData($v['comment_uid'],'id');
                }
                $lists[$key]['tel'] = $user['tel'];
                $lists[$key]['username'] = $user['username'];
            }
        }catch(\Exception $e){
            return admin_json(-1, '获取失败'.$e->getMessage());
        }
        writelog('查看资讯评论列表',1,$user);
        return admin_json(1,'获取成功',[
            'count' => $count,//总记录数
            'allpage' => $allpage,  //总页数
            'lists' => $lists,  //列表数据
        ]);
    }
}